python protocol
Why
interfaceは表面上(signiture?)の整合性を見るだけなので、下部、内部の規約も必要(runtime レベルでは??)
protocolは(実際の ie: メソッド適用) 要件を満たしてるかを見る??(golang の interfaceはprotocol?)
informal interfaces とはそういうイメージだと思った. python protocol#5baf33bc21415f000004514f
What
Abstract Objects Layer — Python 3.7.1 documentation
When used on object types for which they do not apply, they will raise a Python exception.
適用できないものに使うと例外あげます。
解説されてるもの
Python を支える技術 ディスクリプタ編 #pyconjp - Qiita
Python では、特定の性質を持つオブジェクトが実装すべき一連のメソッドのことをプロトコルと呼びます
Interfaces in Python: Protocols and ABCs · Abu Ashraf Masnun
So any object, regardless of it’s class/type, can conform to a certain interface just by implementing the expected behavior (methods). These informal interfaces are termed as protocols.
So we can see that protocols are like informal interfaces
QA
Q: 検索してもうまく情報が集まらない、informalな用語だから?
A: python protocol#5bdf711c21415f00004d8ee8 初手かな。
MISC
file
read
iterator
next?
container
__len__, __contains__,
#python